//
//  AssetsOrderingTableViewCell.m
//  DBAChain
//
//  Created by Mxionlly on 2018/9/7.
//  Copyright © 2018年 Evan. All rights reserved.
//

#import "AssetsOrderingTableViewCell.h"
#import <SDAutoLayout/SDAutoLayout.h>
#import "CommonData.h"

@implementation AssetsOrderingTableViewCell
{
    UILabel         *lbtitle;
    UILabel         *lbtime;
    UILabel         *lbmoney;
    UILabel         *lbcontent;
    UIButton        *deleteButton;
    UIView          *baseView;
    UIView          *leftView;
    UITapGestureRecognizer *_tap;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
        [self addGestures];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)setup{
    baseView = [UIView new];
    baseView.backgroundColor = [UIColor clearColor];
    
    lbtitle = [UILabel new];
    lbtitle.textColor = UIColorFromRGB(0xF05CA4);
    lbtitle.font = [UIFont systemFontOfSize:16];
    
    deleteButton = [UIButton new];
    deleteButton.backgroundColor = [UIColor blackColor];
    deleteButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [deleteButton setTitle:@"取消挂单" forState:UIControlStateNormal];
    [deleteButton addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];

    lbmoney = [UILabel new];
    lbmoney.textAlignment = NSTextAlignmentRight;
    lbmoney.textColor = UIColorFromRGB(0x333333);
    lbmoney.font = [UIFont systemFontOfSize:16];

    
    lbtime = [UILabel new];
    lbtime.textColor = UIColorFromRGB(0xA5A5A5);
    lbtime.font = [UIFont systemFontOfSize:12];
    
    lbcontent = [UILabel new];
    lbcontent.textAlignment = NSTextAlignmentRight;
    lbcontent.textColor = UIColorFromRGB(0xA5A5A5);
    lbcontent.font = [UIFont systemFontOfSize:12];
    
    leftView = [UIView new];
    leftView.backgroundColor = [UIColor clearColor];
    
    NSArray *views = @[baseView,deleteButton,leftView];
    NSArray *views1 = @[lbtitle,lbmoney,lbtime,lbcontent];
    [baseView sd_addSubviews:views1];
    [self.contentView sd_addSubviews:views];
    
    UIView *contentView = self.contentView;
    
    deleteButton.sd_layout.rightEqualToView(contentView).bottomEqualToView(contentView).topEqualToView(contentView).widthIs(0);
    baseView.sd_layout.topEqualToView(contentView).heightIs(74).rightSpaceToView(deleteButton, 0).widthIs(KScreenWidth);
    leftView.sd_layout.rightEqualToView(contentView).widthIs(50).topEqualToView(contentView).bottomEqualToView(contentView);
    lbtitle.sd_layout.leftSpaceToView(baseView, 15).heightIs(21).topSpaceToView(baseView, 15).autoWidthRatio(10);
    lbmoney.sd_layout.heightIs(21).topEqualToView(lbtitle).rightSpaceToView(baseView, 15).minWidthIs(100);
    lbtime.sd_layout.leftEqualToView(lbtitle).heightIs(21).topSpaceToView(lbtitle, 5).minWidthIs(120);
    lbcontent.sd_layout.rightEqualToView(lbmoney).heightIs(21).topSpaceToView(lbtitle, 5).leftSpaceToView(lbtime, 10).autoWidthRatio(10);
    lbcontent.text = @"单价: 5 CNY 限额: 1000-2000 CNY";
    lbtime.text = @"18/06/24 16:23";
    lbmoney.text =@"2000000000 CNY";
    lbtitle.text = @"680 GTE";
}

- (void)setBuyData:(dataOrderBuyAndSaleInfo*)orderinfo{
    lbcontent.text = [NSString stringWithFormat:@"单价: %@ CNY 限额: %@ CNY",orderinfo.price,orderinfo.limitAmount];
    lbtime.text = orderinfo.orderTime;//@"18/06/24 16:23";
    lbmoney.text = orderinfo.rmbAmount;//@"2000000000 CNY";
    lbtitle.text = [NSString stringWithFormat:@"%@ GTE",orderinfo.gteCoin];
}

-(void)deleteAction:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(didDeleteAction:)]) {
        [self.delegate didDeleteAction:nil];
    }
}

- (void)addGestures
{
    //添加点击手势
    _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backToOrginPoint)];
    _tap.enabled = NO;
    [leftView addGestureRecognizer:_tap];
    
    //拖动手势
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    panGesture.delegate = self;
    panGesture.delaysTouchesBegan = 0.5;
    [leftView addGestureRecognizer:panGesture];
    [panGesture requireGestureRecognizerToFail:_tap];
}

- (void)pan:(UIPanGestureRecognizer *)gesture
{
    deleteButton.sd_layout.widthIs(80);
    if ([self.delegate respondsToSelector:@selector(showDeleteView:)]) {
        [self.delegate showDeleteView:deleteButton.tag];
    }
}

-(void)backToOrginPoint
{
    NSLog(@"____________backToOrginPoint");
}

-(void)setModel:(dataOrderInfoList *)model
{
    lbmoney.text = [NSString stringWithFormat:@"%@ CNY",model.orderAmount];
    lbcontent.text = [NSString stringWithFormat:@"单价: %@ CNY 限额: 1000-2000 CNY",model.price];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
